/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVA-Data-Structures-and-Algorithms PROJECT
 * All Rights Reserved.
 */

package 二叉树.删除节点;

import 节点.Node;

/**
 * @Description 删除节点
 * 如果删除的节点是叶子节点，则删除该节点
 * 如果删除的节点是非叶子节点，则删除该子树.
 * @Author 俊昭
 * @Date 2022/5/5
 */
public class BinaryTree {
    // 构造一个二叉树
    private static Node root = new Node(1, "宋江");

    static {// 手动创建 暂时
        root.left = new Node(2, "卢俊义");
        root.right = new Node(3, "吴用");
        root.left.left = new Node(4, "公孙胜");
        root.left.right = new Node(5, "关胜");
        root.right.left = new Node(6, "林冲");
        root.right.right = new Node(7, "秦明");
//        root.left.left.left = new Node(8,"呼延灼");
//        root.left.left.right = new Node(9,"花荣");
    }

    /**
     * @param no 要删除的节点
     * @description 删除节点
     * @author 俊昭
     * @date 2022/5/5
     */
    public static void del(int no) {
        if (root.getNo() == no) {
            root = null;
            return;
        }
        root.del(no);
    }

    /**
     * @description 前序遍历
     * @author 俊昭
     * @date 2022/5/4
     */
    public static void preTraversal() {
        if (root != null) {
            root.preTraversal();
        } else {
            System.out.println("null");
        }
    }


}
